"""
# -*- coding: utf-8 -*-
# @Time : 2023/4/23 7:11
# @Author : LTY
# @File : L231_PP_DishIN_Page_test.py
# @function : python3.9.2
"""

import sys
import time
import serial
import serial.tools.list_ports
import binascii
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QRegExpValidator, QIntValidator, QIcon
from PyQt5.QtCore import QRegExp            # QT里面正则表达式的类
from PyQt5.QtCore import Qt

from ui_QT.ui_DishINPage import Ui_MainWindow as DishIN_ui_Main
from L231_PP_RSB4BQTtest_LTY_230414 import L231_PP_Main_Page_test as Main_Func

Serial_code_type1_item = ''
Serial_code_type1 = ''
Serial_code_type2 = b''
receive_code_type1_item = ''
receive_code_type1 = ''
receive_code_type2 = b''


class QT_DishIN(QMainWindow):

    def __init__(self, parent=None):
        super().__init__(parent)  # 调用父类构造函数，创建窗体
        self.ui_Func = DishIN_ui_Main()  # 创建UI对象
        self.ui_Func.setupUi(self)  # 构造UI界面
        self.ser = serial.Serial()
        self.textEdit = self.ui_Func.textEdit
        self.cap_data = []
        self.initUI()
        self.Serial_code_type1 = ''
        self.Serial_code_type2 = b''
        self.receive_code_type1 = ''
        self.receive_code_type2 = b''

        # 接收数据和发送数据数目置零
        self.data_num_received = 0
        self.data_num_sended = 0

##  ==============自定义功能函数========================
    def initUI(self):
        self.setWindowTitle('增加平皿页面')

        # 按钮设置
        self.button_return = self.ui_Func.pushButton_return
        self.button_return.clicked.connect(self.RETURN)
        self.button_return.setShortcut("Esc")
        self.button_send_RSB4B = self.ui_Func.pushButton_send_RSB4B
        self.button_send_RSB4B.clicked.connect(self.SEND_RSB4B)

        self.button_select_1 = self.ui_Func.radioButton
        self.button_select_1.setChecked(False)
        self.button_select_1.toggled.connect(self.buttonState)
        self.button_select_2 = self.ui_Func.radioButton_2
        self.button_select_2.setChecked(False)
        self.button_select_2.toggled.connect(self.buttonState)

        # 机器流水号
        DeviSN = self.ui_Func.lineEdit_DeviSN
        reg = QRegExp('[0-9]+$')
        validator = QRegExpValidator()
        validator.setRegExp(reg)
        DeviSN.setValidator(validator)

        intValidator = QIntValidator(self)
        intValidator.setRange(0, 9)
        DeviSN.setValidator(intValidator)

        # 操作员
        OprNam = self.ui_Func.lineEdit_OprNam
        reg = QRegExp('[a-zA-Z0-9_]+$')
        validator = QRegExpValidator()
        validator.setRegExp(reg)
        OprNam.setValidator(validator)

        # 实验名称
        ExpNam = self.ui_Func.lineEdit_ExpNam
        reg = QRegExp('[a-zA-Z0-9_]+$')
        validator = QRegExpValidator()
        validator.setRegExp(reg)
        ExpNam.setValidator(validator)

        ExpNam.setPlaceholderText('数字，字母和下划线')

        # 平皿ID
        DishID = self.ui_Func.lineEdit_DishID
        reg = QRegExp('[0-9]+$')
        validator = QRegExpValidator()
        validator.setRegExp(reg)
        DishID.setValidator(validator)

        DishID.setPlaceholderText('十八位整数')

        # 样品ID
        SampID = self.ui_Func.lineEdit_SampID
        reg = QRegExp('[0-9]+$')
        validator = QRegExpValidator()
        validator.setRegExp(reg)
        SampID.setValidator(validator)

        SampID.setPlaceholderText('十八位整数')

        # 坐标X
        CoordX = self.ui_Func.lineEdit_CoordX
        reg = QRegExp('[0-9]+$')
        validator = QRegExpValidator()
        validator.setRegExp(reg)
        CoordX.setValidator(validator)

        intValidator = QIntValidator(self)
        intValidator.setRange(1, 8)
        CoordX.setValidator(intValidator)

        # 坐标Y
        CoordY = self.ui_Func.lineEdit_CoordY
        reg = QRegExp('[A-Z]+$')
        validator = QRegExpValidator()
        validator.setRegExp(reg)
        CoordY.setValidator(validator)

        Validator = QRegExpValidator(self)
        Validator.setRegExp(reg)
        CoordY.setValidator(Validator)

        # 开始培养时间
        # 年
        year = self.ui_Func.lineEdit_CulTim_year
        reg = QRegExp('[0-9]+$')
        validator = QRegExpValidator()
        validator.setRegExp(reg)
        year.setValidator(validator)

        year.setPlaceholderText('两位整数')
        intValidator = QIntValidator(self)
        intValidator.setRange(1, 99)
        year.setValidator(intValidator)

        # 月
        month = self.ui_Func.lineEdit_CulTim_month
        reg = QRegExp('[0-9]+$')
        validator = QRegExpValidator()
        validator.setRegExp(reg)
        month.setValidator(validator)

        month.setPlaceholderText('两位整数')
        intValidator = QIntValidator(self)
        intValidator.setRange(1, 13)
        month.setValidator(intValidator)

        # 日
        date = self.ui_Func.lineEdit_CulTim_date
        reg = QRegExp('[0-9]+$')
        validator = QRegExpValidator()
        validator.setRegExp(reg)
        date.setValidator(validator)

        date.setPlaceholderText('两位整数')
        intValidator = QIntValidator(self)
        intValidator.setRange(1, 32)
        date.setValidator(intValidator)

        # 时
        hour = self.ui_Func.lineEdit_CulTim_hour
        reg = QRegExp('[0-9]+$')
        validator = QRegExpValidator()
        validator.setRegExp(reg)
        hour.setValidator(validator)

        hour.setPlaceholderText('两位整数')
        intValidator = QIntValidator(self)
        intValidator.setRange(1, 24)
        hour.setValidator(intValidator)

        # 分
        minute = self.ui_Func.lineEdit_CulTim_minute
        reg = QRegExp('[0-9]+$')
        validator = QRegExpValidator()
        validator.setRegExp(reg)
        minute.setValidator(validator)

        minute.setPlaceholderText('两位整数')
        intValidator = QIntValidator(self)
        intValidator.setRange(1, 61)
        minute.setValidator(intValidator)

        # 秒
        second = self.ui_Func.lineEdit_CulTim_second
        reg = QRegExp('[0-9]+$')
        validator = QRegExpValidator()
        validator.setRegExp(reg)
        second.setValidator(validator)

        second.setPlaceholderText('两位整数')
        intValidator = QIntValidator(self)
        intValidator.setRange(1, 61)
        second.setValidator(intValidator)

        # 开始拍照时间
        # 年
        year = self.ui_Func.lineEdit_BegTim_year
        reg = QRegExp('[0-9]+$')
        validator = QRegExpValidator()
        validator.setRegExp(reg)
        year.setValidator(validator)

        year.setPlaceholderText('两位整数')
        intValidator = QIntValidator(self)
        intValidator.setRange(1, 99)
        year.setValidator(intValidator)

        # 月
        month = self.ui_Func.lineEdit_BegTim_month
        reg = QRegExp('[0-9]+$')
        validator = QRegExpValidator()
        validator.setRegExp(reg)
        month.setValidator(validator)

        month.setPlaceholderText('两位整数')
        intValidator = QIntValidator(self)
        intValidator.setRange(1, 13)
        month.setValidator(intValidator)

        # 日
        date = self.ui_Func.lineEdit_BegTim_date
        reg = QRegExp('[0-9]+$')
        validator = QRegExpValidator()
        validator.setRegExp(reg)
        date.setValidator(validator)

        date.setPlaceholderText('两位整数')
        intValidator = QIntValidator(self)
        intValidator.setRange(1, 32)
        date.setValidator(intValidator)

        # 时
        hour = self.ui_Func.lineEdit_BegTim_hour
        reg = QRegExp('[0-9]+$')
        validator = QRegExpValidator()
        validator.setRegExp(reg)
        hour.setValidator(validator)

        hour.setPlaceholderText('两位整数')
        intValidator = QIntValidator(self)
        intValidator.setRange(1, 24)
        hour.setValidator(intValidator)

        # 分
        minute = self.ui_Func.lineEdit_BegTim_minute
        reg = QRegExp('[0-9]+$')
        validator = QRegExpValidator()
        validator.setRegExp(reg)
        minute.setValidator(validator)

        minute.setPlaceholderText('两位整数')
        intValidator = QIntValidator(self)
        intValidator.setRange(1, 61)
        minute.setValidator(intValidator)

        # 秒
        second = self.ui_Func.lineEdit_BegTim_second
        reg = QRegExp('[0-9]+$')
        validator = QRegExpValidator()
        validator.setRegExp(reg)
        second.setValidator(validator)

        second.setPlaceholderText('两位整数')
        intValidator = QIntValidator(self)
        intValidator.setRange(1, 61)
        second.setValidator(intValidator)

    def RETURN(self):
        text = self.sender().text()
        if text == "返回":
            reply = QMessageBox.question(self, 'Return', '您是否要返回', QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
            if reply == QMessageBox.Yes:
                self.ui_Begin = Main_Func.QT_Function()
                self.close()
                self.ui_Begin.show()

    # 打开串口
    def port_open(self):
        self.ser.port = 'COM3'
        self.ser.baudrate = 9600
        self.ser.bytesize = 8
        self.ser.stopbits = 1

        try:
            self.ser.open()
        except:
            QMessageBox.critical(self, "Port Error", "此串口不能被打开！")
            return None

    # 关闭串口
    def port_close(self):
        try:
            self.ser.close()
        except:
            # 接收数据和发送数据数目置零
            self.data_num_received = 0
            self.data_num_sended = 0

    def calc(self):
        DeviSN = self.ui_Func.lineEdit_DeviSN.text()
        OprNam = self.ui_Func.lineEdit_OprNam.text()
        ExpNam = self.ui_Func.lineEdit_ExpNam.text()
        DishID = self.ui_Func.lineEdit_DishID.text()
        SampID = self.ui_Func.lineEdit_SampID.text()
        CoordX = self.ui_Func.lineEdit_CoordX.text()
        CoordY = self.ui_Func.lineEdit_CoordY.text()

        if self.ui_Func.lineEdit_DeviSN.text() == '' or self.ui_Func.lineEdit_OprNam.text() == '' \
                or self.ui_Func.lineEdit_ExpNam.text() == '' or self.ui_Func.lineEdit_DishID.text() == '' \
                or self.ui_Func.lineEdit_SampID.text() == '' or self.ui_Func.lineEdit_CoordX.text() == '' \
                or self.ui_Func.lineEdit_CoordY.text() == '':

            UNCOMPLETE_ANSWER = 'CONTINUE_INPUT'
            return UNCOMPLETE_ANSWER

        else:
            # print(type(DishID))
            global Serial_code_type1_item
            global Serial_code_type1
            global Serial_code_type2

            Serial_code_type1_list = [b'~', b'6', b'3', b'79']
            Serial_code_type2 = b'\x7e\x06\x03\x4F'
            Items = []

            DeviSN_item = (ord(str(DeviSN))).to_bytes(1, 'big')
            # print(DeviSN_item)
            Items.append(DeviSN_item)

            OprNam_list = []
            for i in range(0, len(OprNam)):
                OprNam_item = (ord(str(OprNam[i]))).to_bytes(1, 'big')
                OprNam_list.append(OprNam_item)
            # print(OprNam_list)
            Items = Items + OprNam_list
            # print(Items)

            ExpNam_list = []
            for i in range(0, len(ExpNam)):
                ExpNam_item = (ord(str(ExpNam[i]))).to_bytes(1, 'big')
                ExpNam_list.append(ExpNam_item)
            # print(ExpNam_list)
            Items = Items + ExpNam_list
            # print(Items)

            DishID_list = []
            for i in range(0, len(DishID)):
                DishID_item = (ord(str(int(DishID[i])))).to_bytes(1, 'big')
                DishID_list.append(DishID_item)
            # print(DishID_list)
            Items = Items + DishID_list

            SampID_list = []
            for i in range(0, len(SampID)):
                SampID_item = (ord(str(int(SampID[i])))).to_bytes(1, 'big')
                SampID_list.append(SampID_item)
            # print(SampID_list)
            Items = Items + SampID_list

            CulTim_year = self.ui_Func.lineEdit_CulTim_year.text()
            CulTim_month = self.ui_Func.lineEdit_CulTim_month.text()
            CulTim_date = self.ui_Func.lineEdit_CulTim_date.text()
            CulTim_hour = self.ui_Func.lineEdit_CulTim_hour.text()
            CulTim_minute = self.ui_Func.lineEdit_CulTim_minute.text()
            CulTim_second = self.ui_Func.lineEdit_CulTim_second.text()

            CulTim_year_tens = (ord(str(int(int(CulTim_year) / 10)))).to_bytes(1, 'big')
            CulTim_year_unit = (ord(str(int(int(CulTim_year) % 10)))).to_bytes(1, 'big')
            CulTim_month_tens = (ord(str(int(int(CulTim_month) / 10)))).to_bytes(1, 'big')
            CulTim_month_unit = (ord(str(int(int(CulTim_month) % 10)))).to_bytes(1, 'big')
            CulTim_date_tens = (ord(str(int(int(CulTim_date) / 10)))).to_bytes(1, 'big')
            CulTim_date_unit = (ord(str(int(int(CulTim_date) % 10)))).to_bytes(1, 'big')
            CulTim_hour_tens = (ord(str(int(int(CulTim_hour) / 10)))).to_bytes(1, 'big')
            CulTim_hour_unit = (ord(str(int(int(CulTim_hour) % 10)))).to_bytes(1, 'big')
            CulTim_minute_tens = (ord(str(int(int(CulTim_minute) / 10)))).to_bytes(1, 'big')
            CulTim_minute_unit = (ord(str(int(int(CulTim_minute) % 10)))).to_bytes(1, 'big')
            CulTim_second_tens = (ord(str(int(int(CulTim_second) / 10)))).to_bytes(1, 'big')
            CulTim_second_unit = (ord(str(int(int(CulTim_second) % 10)))).to_bytes(1, 'big')
            CulTim_data_list = [CulTim_year_tens, CulTim_year_unit, CulTim_month_tens, CulTim_month_unit, CulTim_date_tens,
                                CulTim_date_unit, CulTim_hour_tens, CulTim_hour_unit, CulTim_minute_tens, CulTim_minute_unit,
                                CulTim_second_tens, CulTim_second_unit]
            Items.extend(CulTim_data_list)

            BegTim_year = self.ui_Func.lineEdit_BegTim_year.text()
            BegTim_month = self.ui_Func.lineEdit_BegTim_month.text()
            BegTim_date = self.ui_Func.lineEdit_BegTim_date.text()
            BegTim_hour = self.ui_Func.lineEdit_BegTim_hour.text()
            BegTim_minute = self.ui_Func.lineEdit_BegTim_minute.text()
            BegTim_second = self.ui_Func.lineEdit_BegTim_second.text()

            BegTim_year_tens = (ord(str(int(int(BegTim_year) / 10)))).to_bytes(1, 'big')
            BegTim_year_unit = (ord(str(int(int(BegTim_year) % 10)))).to_bytes(1, 'big')
            BegTim_month_tens = (ord(str(int(int(BegTim_month) / 10)))).to_bytes(1, 'big')
            BegTim_month_unit = (ord(str(int(int(BegTim_month) % 10)))).to_bytes(1, 'big')
            BegTim_date_tens = (ord(str(int(int(BegTim_date) / 10)))).to_bytes(1, 'big')
            BegTim_date_unit = (ord(str(int(int(BegTim_date) % 10)))).to_bytes(1, 'big')
            BegTim_hour_tens = (ord(str(int(int(BegTim_hour) / 10)))).to_bytes(1, 'big')
            BegTim_hour_unit = (ord(str(int(int(BegTim_hour) % 10)))).to_bytes(1, 'big')
            BegTim_minute_tens = (ord(str(int(int(BegTim_minute) / 10)))).to_bytes(1, 'big')
            BegTim_minute_unit = (ord(str(int(int(BegTim_minute) % 10)))).to_bytes(1, 'big')
            BegTim_second_tens = (ord(str(int(int(BegTim_second) / 10)))).to_bytes(1, 'big')
            BegTim_second_unit = (ord(str(int(int(BegTim_second) % 10)))).to_bytes(1, 'big')
            BegTim_data_list = [BegTim_year_tens, BegTim_year_unit, BegTim_month_tens, BegTim_month_unit, BegTim_date_tens,
                                BegTim_date_unit, BegTim_hour_tens, BegTim_hour_unit, BegTim_minute_tens, BegTim_minute_unit,
                                BegTim_second_tens, BegTim_second_unit]
            Items.extend(BegTim_data_list)

            CoordX_item = (ord(str(CoordX))).to_bytes(1, 'big')
            Items.append(CoordX_item)

            CoordY_item = (ord(str(CoordY))).to_bytes(1, 'big')
            Items.append(CoordY_item)
            # print(Items)

            pre_check_code = 88
            for i in range(0, len(Items)):
                pre_check_code += int(binascii.b2a_hex(Items[i]), base=16)
            check_code = pre_check_code & 0xFF  # 取低八位
            # print(pre_check_code)
            # print(check_code)
            byte_check_code = check_code.to_bytes(1, 'big')
            Items.append(byte_check_code)
            Items.append(b'\xe7')
            # print(byte_check_code)
            # print(Items)

            Serial_code_type1_list.extend(Items)
            for item in Serial_code_type1_list:
                item = hex(int.from_bytes(item, byteorder='big'))
                Serial_code_type1_item = Serial_code_type1_item + '\\' + str(item)
            Serial_code_type1 = Serial_code_type1_item
            self.Serial_code_type1 = Serial_code_type1
            Serial_code_type1_item = ''
            print("Serial_code_type1 = ", self.Serial_code_type1)
            # self.ui_Func.textEdit_send_commod.setText(str(Serial_code_type1))

            for i in range(0, len(Items)):
                Serial_code_type2 += Items[i]
                self.Serial_code_type2 = Serial_code_type2
            print("Serial_code_type2 = ", self.Serial_code_type2)
            # self.ui_Func.textEdit_send_commod.setText(str(Serial_code_type2))
            # self.Items.clear()

            return Serial_code_type2

    def Textviewer(self, file_create_time):
        DishID = self.ui_Func.lineEdit_DishID.text()
        file_name = "\\DishIN_DishID" + DishID + "_TIME" + file_create_time + ".txt"
        address = "Z:\Exp_File\exp" + '\\' + "%s" % self.ui_Func.lineEdit_ExpNam.text() + "\DishID" + DishID + file_name

        with open(address, 'r') as f:
            if f:
                my_file = f.read()
                self.textEdit.setText(my_file)
            else:
                dialog = QDialog()
                dialog.resize(230, 80)
                label1 = QLabel(dialog)
                label1.setText("未找到指定文件")
                label1.move(65, 10)
                button = QPushButton('确定', dialog)
                button.clicked.connect(dialog.close)
                button.move(70, 40)
                dialog.setWindowTitle('无法打开文件')
                dialog.setWindowModality(Qt.ApplicationModal)  # 防止子窗口响应后，主串口继续相应
                dialog.exec()

    def SEND_RSB4B(self):
        INPUT_ANSWER = self.calc()
        if INPUT_ANSWER == 'CONTINUE_INPUT':
            dialog = QDialog()
            dialog.resize(230, 80)
            label1 = QLabel(dialog)
            label1.setText("请输入完整信息")
            label1.move(65, 10)
            button = QPushButton('继续输入', dialog)
            button.clicked.connect(dialog.close)
            button.move(70, 40)
            dialog.setWindowTitle('信息不全')
            dialog.setWindowModality(Qt.ApplicationModal)  # 防止子窗口响应后，主串口继续相应
            dialog.exec()
        else:
            address = r"C:\Users\lclvlb\Desktop\L231项目周计划与周报\L231code\bisheQT\temp.txt"
            file = open(address, 'w')
            text = self.ui_Func.lineEdit_BegTim_year.text() + self.ui_Func.lineEdit_BegTim_month.text() + \
                   self.ui_Func.lineEdit_BegTim_date.text() + self.ui_Func.lineEdit_BegTim_hour.text() + \
                   self.ui_Func.lineEdit_BegTim_minute.text() + self.ui_Func.lineEdit_BegTim_second.text()
            file.write(text)
            file.close()

            address = r"C:\Users\lclvlb\Desktop\L231项目周计划与周报\L231code\bisheQT\FILE.txt"
            file = open(address, 'w')
            text = self.ui_Func.lineEdit_ExpNam.text()
            file.write(text)
            file.close()

            self.ui_Func.lineEdit_BegTim_year.text()
            self.ui_Func.lineEdit_BegTim_month.text()
            self.ui_Func.lineEdit_BegTim_date.text()
            self.ui_Func.lineEdit_BegTim_hour.text()
            self.ui_Func.lineEdit_BegTim_minute.text()
            self.ui_Func.lineEdit_BegTim_second.text()

            try:
                self.port_open()
                # self.ser.flushInput()  # 清空输入缓冲区
                if self.ser.isOpen():
                    self.ser.write(INPUT_ANSWER)

                    frame_header_chack = self.ser.read()
                    if frame_header_chack == b'\x7e':
                        self.cap_data.append(frame_header_chack)
                        for i in range(1, 100):
                            uart_data = self.ser.read()
                            self.cap_data.append(uart_data)

                            # 查询帧尾
                            if self.cap_data[i] == b'\xe7':
                                break

                    # print(self.cap_data)
                    global receive_code_type1_item
                    global receive_code_type1
                    global receive_code_type2

                    receive_code_type2 = b'\x7e\x06\x06'

                    for item in self.cap_data:
                        item = hex(int.from_bytes(item, byteorder='big'))
                        receive_code_type1_item = receive_code_type1_item + '\\' + str(item)
                    receive_code_type1 = receive_code_type1_item
                    self.receive_code_type1 = receive_code_type1
                    receive_code_type1_item = ''
                    # self.ui_Func.textEdit_receive_commod.setText(receive_code_type1)
                    print('receive_code_type1 = ', self.receive_code_type1)

                    for i in range(3, len(self.cap_data)):
                        receive_code_type2 += self.cap_data[i]
                        self.receive_code_type2 = receive_code_type2
                    print('receive_code_type2 = ', self.receive_code_type2)

                    year = chr(int.from_bytes(self.cap_data[4], byteorder='big')) + \
                           chr(int.from_bytes(self.cap_data[5], byteorder='big')) + \
                           chr(int.from_bytes(self.cap_data[6], byteorder='big')) + \
                           chr(int.from_bytes(self.cap_data[7], byteorder='big'))
                    month = chr(int.from_bytes(self.cap_data[8], byteorder='big')) + \
                            chr(int.from_bytes(self.cap_data[9], byteorder='big'))
                    date = chr(int.from_bytes(self.cap_data[10], byteorder='big')) + \
                           chr(int.from_bytes(self.cap_data[11], byteorder='big'))
                    hour = chr(int.from_bytes(self.cap_data[12], byteorder='big')) + \
                           chr(int.from_bytes(self.cap_data[13], byteorder='big'))
                    minute = chr(int.from_bytes(self.cap_data[14], byteorder='big')) + \
                             chr(int.from_bytes(self.cap_data[15], byteorder='big'))
                    second = chr(int.from_bytes(self.cap_data[16], byteorder='big')) + \
                             chr(int.from_bytes(self.cap_data[17], byteorder='big'))
                    file_create_time = year + month + date + hour + minute + second
                    # print(file_create_time)

                    self.port_close()
                    self.cap_data.clear()
                    self.Textviewer(file_create_time)

                else:
                    self.port_close()
                    QMessageBox.critical(self, "Port Error", "传输失败")

            except KeyboardInterrupt:
                self.port_close()

    def button_show_Hex(self):
        self.ui_Func.textEdit_send_commod.setText(Serial_code_type1)
        self.ui_Func.textEdit_receive_commod.setText(receive_code_type1)

    def button_show_ASCII(self):
        self.ui_Func.textEdit_send_commod.setText(str(Serial_code_type2))
        self.ui_Func.textEdit_receive_commod.setText(str(receive_code_type2))

    def buttonState(self):
        radioButton = self.sender()  # 获取自身发出信号的对象
        if radioButton.text() == '显示16进制':
            if radioButton.isChecked() == True:
                self.button_show_Hex()

        if radioButton.text() == '显示ASCII码':
            if radioButton.isChecked() == True:
                self.button_show_ASCII()


##  ============窗体测试程序 ================================
if __name__ == "__main__":  # 用于当前窗体测试
    app = QApplication(sys.argv)  # 创建GUI应用程序
    app.setWindowIcon(QIcon('..\\image\\school(256).ico'))
    form = QT_DishIN()  # 创建窗体
    form.show()

    sys.exit(app.exec_())
